﻿package ui.components{
	import flash.display.Sprite
	import flash.display.DisplayObject
	import flash.geom.Rectangle
	public class Rows extends Component{
		private var _spacing:Number=10
		function Rows(...args:Array){
			for each(var d:DisplayObject in args){
				addChild(d);
			}
		}
		
		public override function addChild(child:DisplayObject):DisplayObject{
			var ret:DisplayObject = super.addChild(child)
			redraw()
			return ret;
		}
		
		public override function addChildAt(child:DisplayObject, index:int):DisplayObject{
			var ret:DisplayObject = super.addChildAt(child,index)
			redraw()
			return ret;
		}
		
		public override function removeChild(child:DisplayObject):DisplayObject{
			var ret:DisplayObject = super.removeChild(child)
			redraw()
			return ret;
		}
		
		public function removeChildren():void{
			while(numChildren)
				super.removeChild(getChildAt(0))
			redraw()
		}

		public function spacing(spacing:Number):*{
			_spacing = spacing
			redraw();
			return this
		}
		
		protected override function redraw():void{
			var top:Number = 0;
			for( var a:int=0;a<numChildren;a++){
				var child:DisplayObject = getChildAt(a);
				child.y = top
				child.width = _width;
				top += child.height + _spacing
			}
			super.redraw()
			_height = top
			
		}
	}
}